<html>
<head>
<link rel="StyleSheet" href="./views/css/human_readable.css" type="text/css" />
<script type="text/javascript" src="./views/js/jquery-1.5.min.js"></script>
<script type="text/javascript">


$(document).ready(function() {
   
});
function show()
{
var ajax_load = "<img class='loading' src='./views/images/loading.gif' alt='loading...' />";
str="uri_txt="+document.getElementById('uri_txt').value.replace('#','%23')+"&endpoint="+document.getElementById('endpoint').value+"&rt="+document.getElementById('rt').value;
$('#txtHint').html(ajax_load)
$.ajax({
    url: './index.php',
    type: 'POST',
	data:str,
    timeout: 1000,
    error: function(){
        alert('Error loading XML document');
    },
    success: function(html){
     $('#txtHint').html(html)
    }
});

}

function traverse(dim_val,dim_uri,obs_uri,dir){
action='nextdimension';
if(dir=='next'){
action='next';
}
else{
action='pre';
}
var ajax_load = "<img class='loading' src='./views/images/loading.gif' alt='loading...' />";
arr_dimuri=document.getElementsByName('dimuri');
arr_dimlab=document.getElementsByName('dimlab');
arr_dimval=document.getElementsByName('dimval');
arr_dimvaluri=document.getElementsByName('dimvaluri');
arr_dimindirect=document.getElementsByName('dimindirect');
measureURI=document.getElementById('measureURI').value;
measurelab=document.getElementById('measurelab').value;
str="rt=uri/traverse"
+"&action="+action
+"&uri_txt="+obs_uri
+"&endpoint="+document.getElementById('endpoint').value
+"&dim_uri="+dim_uri
+"&dim_val="+dim_val
+"&arr_dimuri="+toArray(arr_dimuri).toString()
+"&arr_dimval="+toArray(arr_dimval).toString()
+"&arr_dimlab="+toArray(arr_dimlab).toString()
+"&arr_dimindirect="+toArray(arr_dimindirect).toString()
+"&measureuri="+measureURI
+"&measurelab="+measurelab
+"&arr_dimvaluri="+toArray(arr_dimvaluri).toString();

$('#txtHint').html(ajax_load)
$.ajax({
    url: './index.php',
	data:str,
    type: 'POST',
    timeout: 1000,
	dataType:"json",
    error: function(){
        alert('No Observation exists...');
		window.location="./index.php?uri_txt="+obs_uri.replace('#','%23')+"&endpoint="+document.getElementById('endpoint').value+"&rt=uri/view";
    },
    success: function(o){
    if(o.status==="ok"){
	 window.location="./index.php?uri_txt="+o.uri.replace('#','%23')+"&endpoint="+document.getElementById('endpoint').value+"&rt=uri/view";
	 }

    }
	
	
});
return false;
}
function dimensionTraverse(dim_val_uri,dim_uri,dim_val,dim_lab,indirect,dir){

var ajax_load = "<img class='loading' src='./views/images/loading.gif' alt='loading...' />";

str="rt=uri/dimension_traverse"
+"&endpoint="+document.getElementById('endpoint').value
+"&dim_val_uri="+dim_val_uri
+"&dim_val="+dim_val
+"&dim_lab="+dim_lab
+"&dim_uri="+dim_uri
+"&dir="+dir
+"&indirect="+indirect;

$('#txtHint').html(ajax_load)
$.ajax({
    url: './index.php',
	data:str,
    type: 'POST',
    timeout: 1000,
    error: function(){
        alert('Error loading XML document');
    },
    success: function(html){
    $('#txtHint').html(html);
	 
    }
	
	
});
return false;
}

function toArray(obj) {
  var array = [];
  // iterate backwards ensuring that length is an UInt32
  for (var i = obj.length >>> 0; i--;) { 
    array[i] = obj[i].value;
  }
  return array;
}
</script>
</head>
<body>



<input name="uri_txt" id="uri_txt" type="hidden" value="<?php echo $uri_txt;?>" />
<input name="endpoint" id="endpoint" type="hidden" value="<?php echo $endpoint;?>" />
<input name="rt" id="rt" value="<?php echo $rt;?>" type="hidden"/>

<div class="container">
<div class="center" id="txtHint">



<?php  if($isObservation==true){?>

<hr/>


<?php

print "<table class=\"dimensiontable\" border=\"0\" width=\"100%\">";
print "<tr>";

print "<td colspan=\"2\"><h3 class=\"measure\">
<span>". $observation->measure->label."<input type='hidden' id='measureURI' value='". $observation->measure->URI."' />
<input type='hidden' id='measurelab' value='".$observation->measure->label."' />
</span>
</h3></td></tr>";

print "<tr><td width=\"50%\"><h1 class=\"observation\">
<span>".$observation->observationValue."</span></h1>";

print "</td><td width=\"50%\" class=\"attribute\">";
for( $i =0; $i < count($observation->attribues); $i++ )
{
	   
		if(strcmp($observation->attribues[$i]->label,"")!=0){
		print"<h5 class=\"dimension\">".
		$observation->attribues[$i]->label.
		":</h5>";
		}
		
		if($observation->attribues[$i]->isIndirect==true)$in="0"; else $in="1";
		if(strcmp($observation->attribues[$i]->value,"")!=0){
				print $observation->attribues[$i]->value;
		}
		else 
		{
				print $observation->attribues[$i]->valueURI;
		
		}
		print "<input type='hidden' name='atturi' value='".$observation->attribues[$i]->URI."'></input>";
		print "<input type='hidden' name='attlab' value='".$observation->attribues[$i]->label."'></input>";
	
		print "<input type='hidden' name='attindirect' value='".$in."'></input>";
		print "<input type='hidden' name='attval' value='".$observation->attribues[$i]->value."' ></input>";
		print "<input type='hidden' name='attvaluri' value='".$observation->attribues[$i]->valueURI."' ></input>";
	
}
print "</td>";
print "</tr>";
print "</table><hr/>";

//--------------------------------------------------------------------------------------------

print "<table class=\"dimensiontable\" border=\"0\" width=\"100%\">";



for( $i =0; $i < count($observation->dimensions); $i++ )
{
	print "<tr>";   
		print "<td>
		<h5 class=\"dimension\">".
		$observation->dimensions[$i]->label.
		":</h5></td>";
		if($observation->dimensions[$i]->isIndirect==true)$in="0"; else $in="1";
		if(strcmp($observation->dimensions[$i]->value,"")!=0){
				print "<td>".
			    "<img onclick=\"traverse('".$observation->dimensions[$i]->value."','".$observation->dimensions[$i]->URI."','".$observation->observationURI."','pre')\" src=\"./views/images/left.gif\"/>".
				"<a href=\"#\"  onclick=\"dimensionTraverse('".$observation->dimensions[$i]->valueURI."','".$observation->dimensions[$i]->URI."','".$observation->dimensions[$i]->value."','".$observation->dimensions[$i]->label."','".$in."','none')\">".$observation->dimensions[$i]->value."</a>".
				"<img onclick=\"traverse('".$observation->dimensions[$i]->value."','".$observation->dimensions[$i]->URI."','".$observation->observationURI."','next')\" src=\"./views/images/right.gif\"/></td>";
		}
		else 
		{
		
		print "<td>".$observation->dimensions[$i]->valueURI."</td>";
		
		}
		print "<input type='hidden' name='dimuri' value='".$observation->dimensions[$i]->URI."'></input>";
		print "<input type='hidden' name='dimlab' value='".$observation->dimensions[$i]->label."'></input>";
	
		print "<input type='hidden' name='dimindirect' value='".$in."'></input>";
		print "<input type='hidden' name='dimval' value='".$observation->dimensions[$i]->value."' ></input>";
		print "<input type='hidden' name='dimvaluri' value='".$observation->dimensions[$i]->valueURI."' ></input>";
	print "</tr>";
}

print "</table>";


}
else
{

print "<h3 class=\"measure\">".$notObservation."</h3>";
}

?>









</div>
</div>
</body>
</html>